//
//  RunMainVC.swift
//  BUYOU
//
//  Created by tyuu on 2024/6/2.
//

import UIKit
import JXPagingView
import JXSegmentedView

class RunMainVC: BaseViewController {

    private var segmentedDataSource: JXSegmentedTitleDataSource = {
        var segmeDataSource = JXSegmentedTitleDataSource()
        segmeDataSource.titleNormalColor = .gray
        segmeDataSource.titleSelectedColor = .black
        segmeDataSource.titleNormalFont = UIFont.systemFont(ofSize: 15)
        segmeDataSource.titleSelectedFont = UIFont.systemFont(ofSize: 18)
        segmeDataSource.isTitleColorGradientEnabled = true
        segmeDataSource.isItemSpacingAverageEnabled = false
        segmeDataSource.itemWidth = JXSegmentedViewAutomaticDimension
        segmeDataSource.titles = ["热门活动"]
        return segmeDataSource
    }()
    
    //初始化JXSegmentedView
    private lazy var segmentedView: JXSegmentedView = {
        let segmentedView = JXSegmentedView()
        segmentedView.delegate = self
        segmentedView.dataSource = self.segmentedDataSource
        segmentedView.listContainer = listContainerView
        segmentedView.contentEdgeInsetLeft = 5
        let lineIndicator = JXSegmentedIndicatorLineView()
        lineIndicator.indicatorWidth = JXSegmentedViewAutomaticDimension
        lineIndicator.indicatorColor = .black
        lineIndicator.indicatorWidth = 16
        lineIndicator.indicatorHeight = 4
        segmentedView.indicators = [lineIndicator]
        return segmentedView
    }()
    
    // 列表视图高度封装的类
    private lazy var listContainerView: JXSegmentedListContainerView! = {
        let listContainerView = JXSegmentedListContainerView(dataSource: self)
        listContainerView.listCellBackgroundColor = .clear
        listContainerView.scrollView.isScrollEnabled = false
        return listContainerView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        navigationItem.title = "步友活动"
        
        
        view.addSubview(segmentedView)
        view.addSubview(listContainerView)
        segmentedView.snp.makeConstraints { make in
            make.top.equalTo(view.safeAreaLayoutGuide)
            make.left.right.equalToSuperview().inset(20)
            make.height.equalTo(44)
        }
        
        listContainerView.snp.makeConstraints { make in
            make.top.equalTo(segmentedView.snp.bottom)
            make.left.right.equalToSuperview()
            make.bottom.equalTo(view.safeAreaLayoutGuide)
        }
        
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

/// 列表视图数据源
extension RunMainVC: JXSegmentedListContainerViewDataSource, JXSegmentedViewDelegate {
    
    // 返回列表的数量
    func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
        return segmentedDataSource.titles.count
    }
    
    // 返回遵从协议的实例
    func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
        let listView = RunHomeVC()
        return listView
    }
    
    func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
        
    }
    
}
